package cn.edu.buaa.cnsatm.traffic_big_data_server.aviation.model;

import cn.edu.buaa.cnsatm.traffic_big_data_server.util.JsonArrayToGeoJsonUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author: CHEN LI
 * @className: AirportModel
 * @description: 对机场的数据进行对象的封装
 * @data: 2019-10-13
 **/

public class AirportModel {


    private String ident;
    private String name;
    private String geom;
    private int num;

    public AirportModel(String ident, String name, String geom, int num) {
        this.ident = ident;
        this.name = name;
        this.geom = geom;
        this.num = num;
    }

    public AirportModel(ResultSet resultSet) throws SQLException {
        this.ident = resultSet.getString("ident");
        this.name = resultSet.getString("name");
        this.geom = resultSet.getString("geom");
        this.num = resultSet.getInt("num");
    }

    public String getIdent() {
        return ident;
    }

    public void setIdent(String ident) {
        this.ident = ident;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGeom() {
        return geom;
    }

    public void setGeom(String geom) {
        this.geom = geom;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public JsonObject toGeoJsonFeature(){
        JsonObject json = new JsonObject();
        JsonObject properties = new JsonObject();
        json.addProperty("type","Feature");
        json.add("geometry", (JsonObject) JsonParser.parseString(JsonArrayToGeoJsonUtil.wkbToJson(this.geom)));
        properties.addProperty("ident",this.ident);
        properties.addProperty("name",this.name);
        properties.addProperty("num",this.num);
        json.add("properties",properties);
        return json;
    }
}
